package com.dsteiner.xelavos.client;

import com.dsteiner.widgets.client.SuggestBoxWidget.SuggestBoxDataProvider;
import com.dsteiner.widgets.client.SuggestBoxWidget.SuggestionRequest;
import com.dsteiner.widgets.client.SuggestBoxWidget.SuggestionResult;
import com.dsteiner.xelavos.client.model.MainTabModel;
import com.dsteiner.xelavos.client.rpc.DataService;
import com.google.gwt.http.client.Request;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class SelectedTabSuggestBoxDataProvider implements SuggestBoxDataProvider{
	private final MainTabModel mainTabModel;
	public SelectedTabSuggestBoxDataProvider(MainTabModel mainTabModel) {
		this.mainTabModel = mainTabModel;
	}
	public Request requestSuggestions(SuggestionRequest request,
			final AsyncCallback<SuggestionResult> callback) {
		request.setClassName(mainTabModel.getSelectedTab().getClassName());
		return DataService.Util.getInstance().getSuggestions(request, new AsyncCallback<SuggestionResult>(){
			public void onFailure(Throwable caught) {
				caught.printStackTrace();
				callback.onFailure(caught);
			}
			public void onSuccess(SuggestionResult result) {
				callback.onSuccess(result);
			}
		});
	}
}
